<?php declare(strict_types=1);
/**
 * @author      xianganyall <xianganyall@gmail.com>
 * @copyright   2023-2025 owner
 **/

namespace Srv\Libs\ConfModel;

final class WebSocketConf extends ConfAbstract
{
    public const PREFIX                         = 'WEBSOCKET.';         // 配置前缀[必定点结尾]
    protected string $processPrefix             = 'Srv-';               // 进程前缀
    protected string $host                      = '0.0.0.0';            // 主机地址
    protected int $listen                       = 0;                    // 端口
    protected int $workerNum                    = 4;                    // 工作进程数
    protected int $taskWorkerNum                = 2;                    // Task进程的数
    protected bool $daemonIze                   = false;                // 是否作为守护进程
    protected int $heartbeatIdleTime            = 90;                   // 空闲关闭时间[秒]
    protected int $heartbeatCheckInterval       = 30;                   // 间隔遍历时间[秒]
    protected bool $openEofCheck                = false;                // EOF检测
    protected bool $openLengthCheck             = true;                 // 包检查
    protected int $packageMaxLength             = 2048000;              // 包最大长度[默认:2M]
    protected int $bufferOutputSize             = 2048000;              // End或Write最大长度[默认:2M]
    protected int $packageLengthOffset          = 0;                    // 包头偏移数
    protected string $packageLengthType         = 'N';                  // 格式类型[N=4]
    protected int $packageBodyOffset            = 4;                    // 包内容偏移数
    protected int $dispatchMode                 = 2;                    // 固定模式
    protected int $maxRequest                   = 4096;                 // 最大任务数
    protected int $maxWaitTime                  = 3;                    // 重载最大等待时长[秒]
    protected int $backlog                      = 128;                  // 队列长度
    protected string $user                      = '';                   // 进程用户名
    protected string $group                     = '';                   // 进程用户组
    protected string $pidFile                   = '';                   // PID文件地址
    protected string $logFile                   = '';                   // 日志文件地址
    protected int $logLevel                     = 3;                    // 日志等级[0-6]
    private string $chRootPath                  = '';                   // 系统根目录
    protected string $subProtocol               = '';                   // 设置WebSocket子协议
    protected int $uploadMaxSize                = 0;                    // 上传最大文件大小[字节]
    protected string $uploadTmpPath             = '';                   // 上传Tmp目录[暂存上传的文件]
    protected string $docRootPath               = '';                   // 站点Root目录[配合静态资源]
    protected bool $autoIndex                   = false;                // 启用索引文件列表
    protected bool $docStatic                   = true;                 // 启用静态资源访问
    protected array $docStaticPaths             = [];                   // 静态资源[必须/目录开头]
    protected array $indexFiles                 = [];                   // 索引文件的文件名[index.html]

    /**
     * @param array $confData
     */
    public function __construct(array $confData)
    {
        $this->init($confData);
    }

    /**
     * @param string $chRootPath
     */
    public function setChRootPath(string $chRootPath):void
    {
        $this->chRootPath = $chRootPath;
    }

    /**
     * @return string
     */
    public function getProcessPrefix(): string
    {
        return $this->processPrefix;
    }

    /**
     * @return string
     */
    public function getHost(): string
    {
        return $this->host;
    }

    /**
     * @return int
     */
    public function getListen(): int
    {
        return $this->listen;
    }

    /**
     * @return int
     */
    public function getWorkerNum(): int
    {
        return $this->workerNum;
    }

    /**
     * @return int
     */
    public function getTaskWorkerNum(): int
    {
        return $this->taskWorkerNum;
    }

    /**
     * @return bool
     */
    public function isDaemonIze(): bool
    {
        return $this->daemonIze;
    }

    /**
     * @return int
     */
    public function getHeartbeatIdleTime(): int
    {
        return $this->heartbeatIdleTime;
    }

    /**
     * @return int
     */
    public function getHeartbeatCheckInterval(): int
    {
        return $this->heartbeatCheckInterval;
    }

    /**
     * @return bool
     */
    public function isOpenEofCheck(): bool
    {
        return $this->openEofCheck;
    }

    /**
     * @return bool
     */
    public function isOpenLengthCheck(): bool
    {
        return $this->openLengthCheck;
    }

    /**
     * @return int
     */
    public function getPackageMaxLength(): int
    {
        return $this->packageMaxLength;
    }

    /**
     * @return int
     */
    public function getBufferOutputSize(): int
    {
        return $this->bufferOutputSize;
    }

    /**
     * @return int
     */
    public function getPackageLengthOffset(): int
    {
        return $this->packageLengthOffset;
    }

    /**
     * @return string
     */
    public function getPackageLengthType(): string
    {
        return $this->packageLengthType;
    }

    /**
     * @return int
     */
    public function getPackageBodyOffset(): int
    {
        return $this->packageBodyOffset;
    }

    /**
     * @return int
     */
    public function getDispatchMode(): int
    {
        return $this->dispatchMode;
    }

    /**
     * @return int
     */
    public function getMaxRequest(): int
    {
        return $this->maxRequest;
    }

    /**
     * @return int
     */
    public function getMaxWaitTime(): int
    {
        return $this->maxWaitTime;
    }

    /**
     * @return int
     */
    public function getBacklog(): int
    {
        return $this->backlog;
    }

    /**
     * @return string
     */
    public function getUser(): string
    {
        return $this->user;
    }

    /**
     * @return string
     */
    public function getGroup(): string
    {
        return $this->group;
    }

    /**
     * @return string
     */
    public function getPidFile(): string
    {
        return $this->pidFile;
    }

    /**
     * @return string
     */
    public function getLogFile(): string
    {
        return $this->logFile;
    }

    /**
     * @return int
     */
    public function getLogLevel(): int
    {
        return $this->logLevel;
    }

    /**
     * @return string
     */
    public function getChRootPath(): string
    {
        return $this->chRootPath;
    }

    /**
     * @return string
     */
    public function getSubProtocol(): string
    {
        return $this->subProtocol;
    }

    /**
     * @return int
     */
    public function getUploadMaxSize(): int
    {
        return $this->uploadMaxSize;
    }

    /**
     * @return string
     */
    public function getUploadTmpPath(): string
    {
        return $this->uploadTmpPath;
    }

    /**
     * @return string
     */
    public function getDocRootPath(): string
    {
        return $this->docRootPath;
    }

    /**
     * @return bool
     */
    public function isAutoIndex(): bool
    {
        return $this->autoIndex;
    }

    /**
     * @return bool
     */
    public function isDocStatic(): bool
    {
        return $this->docStatic;
    }

    /**
     * @return array
     */
    public function getDocStaticPaths(): array
    {
        return $this->docStaticPaths;
    }

    /**
     * @return array
     */
    public function getIndexFiles(): array
    {
        return $this->indexFiles;
    }
}